﻿@{
    ViewBag.Title = "分配角色";
}
<style type="text/css">
    select {
        height: 200px;
        width: 130px;
    }
    .tbList {
        text-align: center;
        border: 1px solid #ddd;
        border-collapse: collapse;
        margin: 0;
        padding: 0;
        width: 100%;
        border-top-width: 0;
        border-bottom-width: 0;
        border-left-width: 0;
        border-right-width: 0;
    }
    .tbList td, th {
        border: 1px solid #ddd;
        padding: 0 5px;
    }
    .tbList td {
        border: 0 solid white;margin-bottom: 0;
    }
</style>
<script type="text/javascript">
    $(function() {

        $("#roleNames").dblclick(moveRight);
        $("#userNames").dblclick(moveLeft);
        $("#btnSet").click(btnSend);
    });

    //将选中的 角色 移到 用户角色下拉框中
    function moveRight() {
        //var $oldDepartment = $("#roleNames option");
        //获取新选中的 部门选项
        var $selectedRoleName = $("#roleNames option:checked");
        $("#userNames").append($selectedRoleName);
    }

    //将选中的角色 移动到左边
    function moveLeft() {
        var $selectName = $("#userNames option:checked");

        $("#roleNames").append($selectName);


    }
    function btnSend() {
        var id=@ViewBag.rid;
        var $selectName = $("#userNames option");     
            var allRid = $selectName.map(function () { return $(this).val(); }).get().join(", ");           
            $.ajax({
                url: "/Admin/Employee/UserRNameAddd/"+id,
                type: "post",
                data: { ss: allRid },
                success:function(xhrobj) {
                    $.msgProcess(xhrobj, function() {
                        $.globalHelper.closeCommonWindow();
                        //重新请求地址，应为显示角色名称没法reload
                        var $curTab = window.top.$('#tabBox').tabs('getSelected');                                         
                        var $ifrObj = $("iframe", $curTab);                                  
                        $ifrObj.attr("src","/admin/employee/EmpIndex");
                    });
                },
                async:true
                           });       
    }
   
    
</script>
    <table class="tbList" id="tbList">
        <tr>
            <td>角色名称</td>
            <td>选择角色</td>
        </tr>
        <tr>
            <td>
                <select id="roleNames" multiple="multiple" name="roleName">
                    @foreach (var item in ViewBag.roleListAll as IEnumerable<FMS.Model.Role>)
                    {
                        <option value="@item.roleId">@item.roleName</option>
                    }
                </select>
            </td>
            <td>
                <select id="userNames" multiple="multiple" name="role">
                    @foreach (var item in ViewBag.roleList as IEnumerable<FMS.Model.Role>)
                    {
                        <option value="@item.roleId">@item.roleName</option>
                    }
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="submit" value="确定" id="btnSet" name="btnSet" style="height: 27px; width: 56px; margin-top: 6px;cursor:pointer" />
            </td>
        </tr>
    </table>


